﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace  SqlDao
{
    /// <summary>
    ///  SqlServer Connection String Builder
    /// </summary>
    public class SqlServerConnectionStringBuilder : SqlBuilder
    {


        /// <summary>
        /// 构建连接字符串
        /// 如 ："Data Source = {ip},{port};Network Library = DBMSSOCN;Initial Catalog = {dbname};User ID = {username};Password = {pwd};CharSet=utf8;pooling={true};";
        /// </summary>
        /// <param name="server">数据源 | IP</param>
        /// <param name="dbName">数据库存名称</param>
        /// <param name="userId">用户名称</param>
        /// <param name="password">密码</param>
        /// <param name="port">端口</param>
        /// <param name="polling">启用线程池</param>
        /// <returns></returns>
        public static String GetConnectionString(string server, string dbName, string userId, string password, int port = 1433, bool polling = true)
        {
            //Trusted_Connection = False;可替代的标准安全连接
            //Integrated Security = SSPI
            string template = "Data Source = {0},{1};Network Library = DBMSSOCN;Initial Catalog = {2};User ID = {3};Password = {4};pooling={5};";
            return string.Format(template,server,port,dbName,userId,password,polling);
        }

    }
}
